App.controller('busStickerTasksController', ['$rootScope', '$scope', '$state', 'Page', function($rootScope, $scope, $state, Page) {
	$scope.orderType = '1';
	$scope.workbillType = '1';
	
    Page.ajaxPost('employeeGroup/empTree.do', null, function(resp) {
        $scope.empList = resp.data;
    });
	
	Page.ajaxPostQuiet('customer/list.do', null, function (resp) {
        $scope.customerList = resp.data;
	});
	
	$scope.steps = [];
	$($rootScope.options.task_type).each(function(i,s){
		if(s.value == '1' || s.value == '2' || s.value == '3'){
			$scope.steps.push({
    			value : s.value,
    			name : s.name
    		});
		}
	});
	
	$scope.getCustomerName = function(customerId){
		var customerName = '';
  	  	$($scope.customerList).each(function(idx,customer){
  	  		if(customer.customerId == customerId){
  	  			customerName = customer.customerName;
  	  			return false;
  	  		}
  	  	});
  	  	return customerName;
	};
	
    $scope.grid = {
        column_defs: [
         {
            target : 14,
            buttons : [
                {
                    name: '办理',
                    class: 'btn-warning btm-sm',
                    icon: 'fa-edit',
                    visiable: function(row) {
                        return row.status && row.status == '1';
                    },
                    event: function(row){
                    	$scope.orderItem = angular.copy(row);
                    	$scope.task = row;
                    	if(!$scope.task.groupTasks){
                    		Page.ajaxPostQuiet('workbill/task/tasksOfOrderItem.do', {orderItemId : row.orderItemId}, function (resp) {
                        		$scope.task.groupTasks = resp.data;
                        		$scope.taskDealModal.show();
                        	});
                    	}else{
                    		$scope.taskDealModal.show();
                    	}
                    }
                },
                {
                    name: '查看',
                    class: 'btn-warning btm-sm',
                    icon: 'fa-edit',
                    visiable: function(row) {
                        return row.status && row.status == '2';
                    },
                    event: function(row){
                    	$scope.orderItem = angular.copy(row);
                    	$scope.task = row;
                    	if(!$scope.task.groupTasks){
                    		Page.ajaxPostQuiet('workbill/task/tasksOfOrderItem.do', {orderItemId : row.orderItemId}, function (resp) {
                        		$scope.task.groupTasks = resp.data;
                        		$scope.taskViewModal.show();
                        	});
                    	}else{
                    		$scope.taskViewModal.show();
                    	}
                    }
                }
            ]
        }],
        submitTask : function(){
        	Page.ajaxPostQuiet('workbill/task/complete.do', $scope.task, function (resp) {
        		Page.alert('任务提交成功');
        		$scope.grid.query();
        		$scope.taskDealModal.hide();
        	});
        },
        cancel : function(){
        	$scope.taskDealModal.hide();
        }
    };
    
    


}]);